package com.ruoyi.web.controller.app;

import com.ruoyi.app.domain.AppCaseInfo;
import com.ruoyi.app.domain.CaseCountVO;
import com.ruoyi.app.service.IAppCaseInfoService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value="案件信息",tags={"案件信息"})
@RequestMapping("app/case")
@RestController
public class AppCaseController extends  AppBaseController{

    @Autowired
    private IAppCaseInfoService iAppCaseInfoService;

    @GetMapping("/page")
    @ApiOperation(value = "案件分页信息",response=AppCaseInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-TaiChi-Token", value = "apyexnioxzsa11cqxy2ur2p9jkp46hz7",
                    paramType = "header", dataType = "string", required = true),
            @ApiImplicitParam(name="pageNum",value="当前记录起始索引",required=true ),
            @ApiImplicitParam(name="pageSize",value="每页显示记录数",required=true),
            @ApiImplicitParam(name="orderByColumn",value="排序列"),
            @ApiImplicitParam(name="isAsc",value="排序的方向 \"desc\" 或者 \"asc\""),
            @ApiImplicitParam(name="idCard",value="身份证"),
            @ApiImplicitParam(name="caseCompany",value="处罚单位" ),
            @ApiImplicitParam(name="startTime",value="批准时间（开始）"),
            @ApiImplicitParam(name="endTime",value="批准时间（结束）" ),
            @ApiImplicitParam(name="deptCode",value="部门编码" ),
            @ApiImplicitParam(name="state",value="状态 0：未上传回执 1：未注销 -1:已注销" )
    })
    public AjaxResult list(Integer pageNum,Integer pageSize,String name, String idCard, String caseCompany, String startTime, String endTime,String deptCode,String state){
        startPage();
        AppCaseInfo search = new AppCaseInfo();
        search.setPeopleName(name);
        search.setPeopleCard(idCard);
        search.setCaseCompanyName(caseCompany);
        search.setCaseCompanyCode(deptCode);
        search.setState(state);
        if(StringUtils.isNotEmpty(startTime)){
            search.setStartTime(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",startTime));
        }
        if(StringUtils.isNotEmpty(endTime)){
            search.setEndTime(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss",endTime));
        }
        List<AppCaseInfo> list = iAppCaseInfoService.selectAppCaseInfoList(search);
        return AjaxResult.success(getDataTable(list));
    }


    @GetMapping("/info/{id}")
    @ApiOperation(value = "案件详细信息",response=AppCaseInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-TaiChi-Token", value = "apyexnioxzsa11cqxy2ur2p9jkp46hz7",
                    paramType = "header", dataType = "string", required = true),
            @ApiImplicitParam(name="id",value="案件ID"),
    })
    public  AjaxResult info(@PathVariable("id") Long id){
        AppCaseInfo appCaseInfo = iAppCaseInfoService.selectAppCaseInfoById(id);
        return AjaxResult.success(appCaseInfo);
    }


    @GetMapping("/count-list")
    @ApiOperation(value = "案件统计信息",response=AppCaseInfo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "X-TaiChi-Token", value = "apyexnioxzsa11cqxy2ur2p9jkp46hz7",
                    paramType = "header", dataType = "string", required = true),
    })
    public AjaxResult countlist(){
        List<CaseCountVO> list = iAppCaseInfoService.selectCaseCountList(null);
        return AjaxResult.success(list);
    }
}
